﻿using Prism.Mvvm;
using Prism.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using WpfApp31.Views;
using Prism.Regions;
using Prism.Services.Dialogs;
using System.Reflection;

namespace WpfApp31.ViewModels
{
    public class MainViewModel : BindableBase
    {
        private readonly IDialogService dialogService;
        public DelegateCommand<string> OpenCommand { get; private set; }
       
        public MainViewModel(IDialogService dialogService)
        {
            OpenCommand = new DelegateCommand<string>(Open);
            this.dialogService = dialogService;
        }

        private void Open(string obj)
        {
            DialogParameters keys = new DialogParameters();
            keys.Add("Title", "测试弹窗2");//主界面传递Title变量的值给调用的子窗口，子窗口接受后，可改变子窗口的标题
            //打开窗口时可以设置回调函数，当子窗口发生指定事件时，回调函数被调用
            dialogService.ShowDialog(obj,keys,callback =>
            {
               if(callback.Result == ButtonResult.OK)
                {
                    //获取子窗口传递过来的变量名为Value的变量
                    string result = callback.Parameters.GetValue<string>("Value");
                }
            });
        }
    }
}
